const testNumber = /^[a-zA-Z0-9\x2d]{5,}$/;
const testName = /^(\w|[\u4E00-\u9FA5]){3,}$/
const testRealName = /^[\u4E00-\u9FA5]{2,}$/
const testPasswd = /^[\x20-\x7e]{8,}$/;// 任意英文字符
const testEmail = /^\w+@[a-zA-Z0-9]{2,10}(?:\.[a-z]{2,4}){1,3}$/;
const testPhone = /^((0\d{2,3}-\d{7,8})|(1[345789]\d{9}))$/;
const testIdNumber = /(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$)|(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)/
const testDispatches = /^\d+$/

let json = {
    regtime:null,
    logintime:null
};

function test_ipt(reg, $input, $label) {
    if (reg.test($input.val())) {
        $input.removeClass('input-error');
        if ($label !== undefined) $label.removeClass('input-error');
        return true;
    }
    $input.addClass('input-error');
    if ($label !== undefined) $label.addClass('input-error');
    return false;
}



// 点击密码两字显示密码
function showTips ($passwd, $labelPasswd) {
    let windowId;
    let havenClickedOnce = false;// 点击过一次后就不再提示
    let flag1 = true;
    $labelPasswd.hover(function () {
        if (!havenClickedOnce) windowId = layer.tips("点我可以显示密码", $labelPasswd.selector, {tips: 1, time: 0});
    }, function () {
        if (!havenClickedOnce && windowId !== undefined) layer.close(windowId);
        windowId = undefined;
    })
    $labelPasswd.click(function () {
        if (!havenClickedOnce) layer.close(windowId);
        havenClickedOnce = true;
        if ($passwd === null) {
            if ($labelPasswd.prop('type') === 'password')
            $labelPasswd.prop('type', 'text');
            else $labelPasswd.prop('type', 'password');
        } else
            if ($passwd.prop('type') === 'password')
                $passwd.prop('type', 'text');
            else $passwd.prop('type', 'password');
    })
    if ($passwd !== null) {
        let timeout;
        $passwd.hover(function () {
            if (!havenClickedOnce && flag1) timeout = setTimeout(function () {
                windowId = layer.tips("偷偷告诉你，点击右边密码两个字可以显示密码", $passwd.selector, {tips: 1, time: 5000});
                flag1 = false;
            }, 5000);
        }, function () {
            if (timeout !== undefined) clearTimeout(timeout);
            timeout = undefined;
            if (windowId !== undefined) layer.close(windowId);
            windowId = undefined;
        });
    }
}

function setEnterKeyEvent($input, event) {
    $input.focusin(function () {
        $input.bind('input propertychange', function () {
            onkeypress = function (key) {
                if (key.key === 'Enter') {
                    onkeypress = undefined;
                    event();
                }
            };
        });
    })
    $input.focusout(function () {
        onkeypress = undefined;
    })
}

function waitingForNextClick($button, seconds, endingVal) {
    $button.css('width', $button.css('width'));
    $button.attr('disabled', 'disabled');
    $button.val('(' + seconds-- + ')');
    const interval = setInterval(function () {
        $button.val('(' + seconds-- + ')');
        if (seconds < 0) {
            clearInterval(interval);
            $button.removeAttr('disabled');
            $button.val(endingVal);
        }
    }, 1000);
}